package sim;

import java.util.List;
import java.util.concurrent.RecursiveAction;

import animal.Ameise;

public class ParallelSim extends RecursiveAction{	
	private AmeisenSimulation sim;
	private int maxAnts = 5000;
	private List<Ameise> task;
	
	public ParallelSim(AmeisenSimulation sim,List<Ameise> task){
		this.sim = sim;
		this.task = task;
	}
	@Override
	protected void compute() {		
		if(task.size()>maxAnts){
			invokeAll(new ParallelSim(sim, task.subList(0, maxAnts)),
					 new ParallelSim(sim, task.subList(maxAnts, task.size())));
		}else{
			for (Ameise a : task) {
				a.agiere(sim);
			}
		}
	}		
}